<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<form action="" method="">
		<table border="1" cellspacing="0" cellpadding="10px" id="newtable">
			<tr>
				<th></th>
				<th>姓名</th>
				<th>年龄</th>
				<th>性别</th>
				<th>住址</th>
			</tr>
			<tr>
				<td><input type="checkbox" name="" id="" value="" /></td>
				<td>张三</td>
				<td>19</td>
				<td class="sex">男</td>
				<td>福建省</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="" id="" value="" /></td>
				<td>张三</td>
				<td>20</td>
				<td class="sex">女</td>
				<td>福建省</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="" id="" value="" /></td>
				<td>张三</td>
				<td>21</td>
				<td class="sex">男</td>
				<td>福建省</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="" id="" value="" /></td>
				<td>张三</td>
				<td>22</td>
				<td class="sex">女</td>
				<td>福建省</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="" id="" value="" /></td>
				<td>张三</td>
				<td>23</td>
				<td class="sex">男</td>
				<td>福建省</td>
			</tr>
		</table>
		</form>
		<input type="checkbox" name="" id="checkallid1" value="" onclick="Selectall1();"/>全选
		<input type="checkbox" name="" id="checkallid2" value="" onclick="Selectall2();"/>全选男
		<input type="checkbox" name="" id="checkallid3" value="" onclick="Selectall3();"/>全选女
		<button type="button">删除</button>
	</body>
	<script type="text/javascript">
		function Selectall1(){
			var allinp =document.getElementById('newtable');
			// console.log(allinp);
			var inpall = allinp.getElementsByTagName('input');
			console.log(inpall);
			var checkall =document.getElementById('checkallid1').checked;
			console.log(checkall);
			for (var i = 0; i < inpall.length; i++) {
				inpall[i].checked =checkall;
			}
		}
		function Selectall2(){
			var sex1 =document.getElementsByClassName('sex');
			console.log(sex1);
			var checkman =document.getElementById('checkallid2').checked;
			console.log(checkman);
			for (var i = 0; i < sex1.length; i++) {
				if (sex1[i].innerText == '男') {
					var objman = document.getElementById('newtable');
					// console.log(objman);
					var input2 = objman.getElementsByTagName('input');
					input2[i].checked = checkman;
				}
			}
		}
		function Selectall3(){
			var sex2 =document.getElementsByClassName('sex');
			console.log(sex2);
			var checkwoman =document.getElementById('checkallid3').checked;
			console.log(checkwoman);
			for (var i = 0; i < sex2.length; i++) {
				if (sex2[i].innerText == '女') {
					var objwoman = document.getElementById('newtable');
					// console.log(objwoman);
					var input3 = objwoman.getElementsByTagName('input');
					input3[i].checked = checkwoman;
				}
			}
		}
	</script>
</html>
